#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int binarySearch(vector<int>& nums, int target, bool leftMost)
    {
        int ret = -1;
        int n = nums.size();
        int left = 0, right = n - 1;
        while (left <= right)
        {
            int mid = (left + right) / 2;
            if (nums[mid] > target)
            {
                right = mid - 1;
            }
            else if (nums[mid] < target)
            {
                left = mid + 1;
            }
            else
            {
                ret = mid;
                if (leftMost)
                    right = mid - 1;
                else
                    left = mid + 1;
            }
        }
        return ret;
    }
    vector<int> searchRange(vector<int>& nums, int target)
    {
        vector<int> ret(2, -1);
        ret[0] = binarySearch(nums, target, true);
        if (ret[0] == -1)
        {
            return ret;
        }
        ret[1] = binarySearch(nums, target, false);
        return ret;
    }
};